"use strict";(()=>{function T(r,a){(a==null||a>r.length)&&(a=r.length);for(var i=0,e=Array(a);i=r.length?{done:!0}:{done:!1,value:r[e++]}},e:function(t){throw t},f:c}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var n,o=!0,A=!1;return{s:function(){i=i.call(r)},n:function(){var t=i.next();return o=t.done,t},e:function(t){A=!0,n=t},f:function(){try{o||i.return==null||i.return()}finally{if(A)throw n}}}}function y(r,a,i){return(a=H(a))in r?Object.defineProperty(r,a,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[a]=i,r}function k(r,a){var i=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(i!=null){var e,c,n,o,A=[],t=!0,l=!1;try{if(n=(i=i.call(r)).next,a===0){if(Object(i)!==i)return;t=!1}else for(;!(t=(e=n.call(i)).done)&&(A.push(e.value),A.length!==a);t=!0);}catch(m){l=!0,c=m}finally{try{if(!t&&i.return!=null&&(o=i.return(),Object(o)!==o))return}finally{if(l)throw c}}return A}}function L(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function b(r,a){var i=Object.keys(r);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(r);a&&(e=e.filter(function(c){return Object.getOwnPropertyDescriptor(r,c).enumerable})),i.push.apply(i,e)}return i}function d(r){for(var a=1;a1&&arguments[1]!==void 0?arguments[1]:{};return p[r]||Q(x(S,r)),aa(p[r],a)}function Q(r){r&&(p[r.id]=r)}function X(r){return f[r]||q(J(S,r)),f[r]?d({},f[r]):null}function q(r){r&&(f[r.name]=r,Z=Object.keys(r).length)}function $(r){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=X(r)||{},e=i.countries||[];return e.map(function(c){return Y(c,a)})}function w(r){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=$(r,a),e=D(i,1),c=e[0];return c||null}function aa(r,a){if(!r)return null;var i=a||{},e=i.deprecated;r.allTimezones;var c=N(r,W),n=e?r.allTimezones:r.timezones;return d(d({},c),{},{timezones:n})}function M(r){let a=new URL(r||window.location.href),i=a.searchParams.get("ref"),e=a.searchParams.get("source"),c=a.searchParams.get("utm_source"),n=a.searchParams.get("utm_medium"),o=i||e||c||null;return!o&&a.hash&&a.hash.includes("#/portal")?ra(a):{source:o,medium:n||null,url:window.document.referrer||null}}function ra(r){let a=new URL(r.href.replace("/#/portal","")),i=a.searchParams.get("ref"),e=a.searchParams.get("source"),c=a.searchParams.get("utm_source"),n=a.searchParams.get("utm_medium");return{source:i||e||c||null,medium:n||null,url:window.document.referrer||null}}function ia(r){let{source:a,medium:i,url:e}=r,c=a||i||e||null;if(c)try{let n=new URL(c).hostname,o=window.location.hostname;if(n===o)return null}catch{return c}return c}function G(r){let a=M(r);return ia(a)}var ea=["username","user","user_id","userid","password","pass","pin","passcode","token","api_token","email","address","phone","sex","gender","order","order_id","orderid","payment","credit_card"];function B(r,a=ea){let i=JSON.stringify(r);return a.forEach(e=>{i=i.replace(new RegExp(`("${e}"):(".+?"|\\d+)`,"mgi"),'$1:"********"')}),i}function R(r,a={},i=!0){if(i){let e=B(r),c=Object.assign({},JSON.parse(e),a);return JSON.stringify(c)}else{let e=Object.assign({},r,a),c=B(e);return JSON.parse(c)}}var g=class{constructor(a=globalThis.window,i=globalThis.document){this.window=a,this.document=i}getNavigator(){return this.window?.navigator}getLocation(){return this.window?.location}getTimezone(){return this.window?.Intl?.DateTimeFormat().resolvedOptions().timeZone}getCurrentScript(){return this.document?.currentScript}getVisibilityState(){return this.document?.visibilityState}setTimeout(a,i){return this.window?.setTimeout(a,i)}clearTimeout(a){return this.window?.clearTimeout(a)}addEventListener(a,i,e){if(!["window","document"].includes(a))throw new TypeError(`BrowserService.addEventListener: unknown target "${a}". Expected "window" or "document".`);a==="window"?this.window?.addEventListener(i,e):a==="document"&&this.document?.addEventListener(i,e)}removeEventListener(a,i,e){if(!["window","document"].includes(a))throw new TypeError(`BrowserService.removeEventListener: unknown target "${a}". Expected "window" or "document".`);a==="window"?this.window?.removeEventListener(i,e):a==="document"&&this.document?.removeEventListener(i,e)}isTestEnvironment(){return this.window?.__GHOST_SYNTHETIC_MONITORING__===!0?!1:!!(this.window&&(this.window.__nightmare||this.window.navigator?.webdriver||this.window.Cypress))}fetch(a,i){return this.window?.fetch(a,i)}wrapHistoryMethod(a,i){if(this.window?.history?.[a]?.__ghostWrapped)return;let e=this.window?.history?.[a];e&&(this.window.history[a]=(...c)=>{let n=e.apply(this.window.history,c);return i(),n},this.window.history[a].__ghostWrapped=!0)}};var ca="analytics_events",u={host:null,token:null,domain:null,datasource:ca,stringifyPayload:!0,globalAttributes:{}},E=class{constructor(a=new g){this.browser=a,this.isListenersAttached=!1}get isTestEnv(){return this.browser.isTestEnvironment()}initConfig(){let a=this.browser.getCurrentScript();if(!a)return!1;u.host=a.getAttribute("data-host"),u.token=a.getAttribute("data-token")||null,u.domain=a.getAttribute("data-domain"),u.datasource=a.getAttribute("data-datasource")||u.datasource,u.stringifyPayload=a.getAttribute("data-stringify-payload")!=="false";for(let i of a.attributes)i.name.startsWith("tb_")&&(u.globalAttributes[i.name.slice(3)]=i.value);return!!u.host}generateUUID(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{let i=Math.random()*16|0;return(a==="x"?i:i&3|8).toString(16)})}async trackEvent(a,i){try{if(!u.host)throw new Error("Missing required configuration (host)");let e=`${u.host}?name=${encodeURIComponent(u.datasource)}`;u.token&&(e+=`&token=${encodeURIComponent(u.token)}`),i.event_id=this.generateUUID();let c=R(i,u.globalAttributes,u.stringifyPayload),n={timestamp:new Date().toISOString(),action:a,version:"1",payload:c},o=new AbortController,A=this.browser.setTimeout(()=>o.abort(),5e3),t={"Content-Type":"application/json"};u.globalAttributes?.site_uuid&&(t["x-site-uuid"]=u.globalAttributes.site_uuid);let l=await this.browser.fetch(e,{method:"POST",headers:t,body:JSON.stringify(n),signal:o.signal});if(this.browser.clearTimeout(A),!l.ok)throw new Error(`HTTP error! Status: ${l.status}`);return l}catch(e){let c=this.browser.getLocation();return(c?.hostname==="localhost"||c?.hostname==="127.0.0.1")&&console.error("Ghost Stats error:",e),null}}getLocationInfo(){try{let a=this.browser.getTimezone(),i=a?w(a):null,e=this.browser.getNavigator(),c=e?.languages?.[0]||e?.language||"en";return{country:i?i.id:null,locale:c}}catch{return{country:null,locale:"en"}}}trackPageHit(){if(this.isTestEnv)return;let{country:a,locale:i}=this.getLocationInfo(),e=this.browser.getNavigator(),c=this.browser.getLocation(),n=M(c?.href);n.url=G(c?.href)||n.url,this.browser.setTimeout(()=>{this.trackEvent("page_hit",{"user-agent":e?.userAgent,locale:i,location:a,parsedReferrer:n,pathname:c?.pathname,href:c?.href})},300)}setupEventListeners(){if(!this.isListenersAttached){if(this.browser.getVisibilityState()!=="hidden")this.trackPageHit();else{let a=()=>{this.browser.getVisibilityState()==="visible"&&(this.trackPageHit(),this.browser.removeEventListener("document","visibilitychange",a))};this.browser.addEventListener("document","visibilitychange",a)}this.isListenersAttached=!0}}init(){return this.isTestEnv||this.browser.window&&this.browser.window.self!==this.browser.window.top?!1:this.initConfig()?(this.browser.window&&(this.browser.window.Tinybird={trackEvent:(i,e)=>this.trackEvent(i,e),_trackPageHit:()=>this.trackPageHit()}),this.setupEventListeners(),!0):(console.warn("Ghost Stats: Missing required configuration"),!1)}},s=new E;s.init();var fa=()=>s.isTestEnv,ga=s.initConfig.bind(s),ha=s.trackEvent.bind(s),pa=s.getLocationInfo.bind(s),Sa=s.trackPageHit.bind(s),Ma=s.setupEventListeners.bind(s),Ea=s.init.bind(s),Ta=s;})();